package com.zhou.framework.mail;

import com.zhou.framework.util.SettingUtil;
import lombok.Data;
import org.apache.commons.collections.MapUtils;

import java.util.Map;

/**
 * @author lang.zhou
 * @date 2019/12/11
 */
@Data
public class MailServerConfig {
    private String server;
    private int port = 25;
    private String protocol = "smtp";
    private String password;
    private String sendAddress;
    private String sendName;
    private boolean debug = false;


    public static MailServerConfig getLocalMailConfig(){
        Map<String, Object> mail = SettingUtil.getSettingMap("mail");
        MailServerConfig config = new MailServerConfig();
        config.setServer(MapUtils.getString(mail,"server",""));
        config.setPort(MapUtils.getIntValue(mail,"port",25));
        config.setProtocol(MapUtils.getString(mail,"protocol","smtp"));
        config.setSendName(MapUtils.getString(mail,"sendName","梦工厂"));
        config.setSendAddress(MapUtils.getString(mail,"sendAddress",""));
        config.setPassword(MapUtils.getString(mail,"password",""));
        config.setDebug(MapUtils.getBooleanValue(mail,"debug",false));
        return config;
    }
}
